﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PJ.Business
{
    /// <summary>
    /// <see cref="IEntity"/> services interface
    /// </summary>
    public interface IEntityService : IBusinessObjectService
    {
        /// <summary>
        /// Gets the entity
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the entity with the given id does not exist.</exception>
        IEntity GetById(string id);

        /// <summary>
        /// Gets the entity from cache first. If not found in cache, gets the entity from provider.
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the entity with the given id does not exist.</exception>
        IEntity CachedGetById(string id);

        /// <summary>
        /// Finds the entity
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        IEntity FindById(string id);

        /// <summary>
        /// Finds the entity from cache first. If not found in cache, finds the entity from provider.
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        IEntity CachedFindById(string id);
    }

    /// <summary>
    /// <see cref="IEntity"/> services interface
    /// </summary>
    /// <typeparam name="TIEntity">Business <see cref="IEntity">Entity</see> interface type</typeparam>
    public interface IEntityService<TIEntity> : IBusinessObjectService<TIEntity>, IEntityService
        where TIEntity : class, IEntity
    {
        /// <summary>
        /// Gets the entity
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the entity with the given id does not exist.</exception>
        new TIEntity GetById(string id);

        /// <summary>
        /// Gets the entity from cache first. If not found in cache, gets the entity from provider.
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the entity with the given id does not exist.</exception>
        new TIEntity CachedGetById(string id);

        /// <summary>
        /// Finds the entity
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        new TIEntity FindById(string id);

        /// <summary>
        /// Finds the entity from cache first. If not found in cache, finds the entity from provider.
        /// </summary>
        /// <param name="id">Entity id</param>
        /// <returns>The entity instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langref="null"/> or empty.</exception>
        new TIEntity CachedFindById(string id);
    }
}
